package b4.view.component.main
{
	import b4.view.component.basic.BasicWidget;
	
	import flash.display.*;

	public class MainFuncBar extends BasicWidget
	{
		public var storIcon:StorIcon;
		public var packageIcon:PackageIcon;
		public var blackSmithIcon:BlackSmithIcon;
		public var magicIcon:MagicIcon;
		public var unionIcon:UnionIcon;
		public var socialIcon:SocialIcon;
		public var battleArrayIcon:BattleArrayIcon;
		public var humanBeingIcon:HumanBeingIcon;
		public var backHomeIcon:BackHomeIcon;
		
		public function MainFuncBar()
		{
			super();
			//背景
			var bgr:Sprite = new Sprite();
			bgr.width = 510;
			bgr.height = 50;
			addChild(bgr);
			//商城
			storIcon = new StorIcon();
			//包裹
			packageIcon = new PackageIcon();
			//铁匠铺
			blackSmithIcon = new BlackSmithIcon();
			//技能
			magicIcon = new MagicIcon();
			//公会
			unionIcon = new UnionIcon();
			//社交
			socialIcon = new SocialIcon();
			//列阵
			battleArrayIcon = new BattleArrayIcon();
			//人物
			humanBeingIcon = new HumanBeingIcon();
			//返回
			backHomeIcon = new BackHomeIcon();
			refresh();
			this.anchor = BasicWidget.ANCHOR_RIGHT_BOTTOM;
			this.x = -510;
			this.y = -70;
		}
		
		public function refresh():void
		{
			showIcon(storIcon);
			showIcon(packageIcon);
			showIcon(blackSmithIcon);
			showIcon(magicIcon);
			showIcon(unionIcon);
			showIcon(socialIcon);
			showIcon(battleArrayIcon);
			showIcon(humanBeingIcon);
			showIcon(backHomeIcon);
		}
		
		private function showIcon(icon:Sprite):void
		{
			if (icon.parent == null)
				addChild(icon);
			refreshIconPos();
		}
		
		private function hideIcon(icon:Sprite):void
		{
			if (icon.parent != null)
				icon.parent.removeChild(icon);
			refreshIconPos();
		}
		
		private function refreshIconPos():void
		{
			for (var i:int = 1; i < this.numChildren; i++)
			{
				var icon:DisplayObject = this.getChildAt(i);
				icon.x = 510 - 55 * i;
			} 
		}
	}
}